﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AopAlliance.Intercept;
using Spring.Data.NHibernate.Support;

namespace Ld.Host.Server.Core
{
    /// <summary>
    /// 事务管理
    /// </summary>
    public class OpenSessionInViewModule : IMethodInterceptor
    {
        private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(OpenSessionInViewModule));

        public object Invoke(IMethodInvocation invocation)
        {
            SessionScope sessionScope = new SessionScope("appSettings", typeof(SessionScope), false);
            try
            {
                sessionScope.Open();
                object obj = invocation.Proceed();
                return obj;
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
                logger.Error(ex);
                return null;
            }
            finally
            {
                sessionScope.Close();
            }
        }
    }
}
